package com.acme.bankapp.domain;

import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class Client implements Serializable{
	private Gender gender;
	private String name;
	
	private Set<Account> accounts;
	
	public int getNumberOfAccounts() {
		return accounts.size();
	}
	public Client(String name, Gender gender) {
		this.name = name;
		this.gender = gender;
		accounts = new HashSet<Account>();
	}
	public Client() {
		this("",Gender.MALE);
	}
	
	public String getClientSituation() {
		return gender.getStr() + name;
	}
	
	public void addAccount(Account account) {
		accounts.add(account);
	}

	public Set<Account> getAccounts() {
		return Collections.unmodifiableSet(accounts);
	}
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((gender == null) ? 0 : gender.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Client other = (Client) obj;
		if (gender != other.gender)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	public String toString() {
		StringBuffer SB = new StringBuffer().append(gender.getStr()+name).append(" Accounts: \n");
		for (Account acc : accounts) {
			SB.append(acc+"\n");
		}
		return SB.toString();
	}
	
	
}

